package 第三周;

/*
 * @author  YxinMiracle
 * @date  2022-04-27 12:08
 * @Gitee: https://gitee.com/yxinmiracle
 */


import java.util.ArrayList;
import java.util.List;

class TreeNode2 {
    int val;
    TreeNode2 left;
    TreeNode2 right;
    TreeNode2() {}
    TreeNode2(int val) { this.val = val; }
    TreeNode2(int val, TreeNode2 left, TreeNode2 right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

public class 二叉树的中序遍历 {
    public List<Integer> ans;

    public List<Integer> inorderTraversal(TreeNode2 root) {

        ans = new ArrayList<>();
        dfs(root);
        return ans;
    }

    private void dfs(TreeNode2 root) {
        if (root == null) return;
        dfs(root.left);
        ans.add(root.val);
        dfs(root.right);
    }

}
